package handel

import (
	"github.com/gin-gonic/gin"
	"order-go/model"
	"strconv"
)

func PerSonAdd(c *gin.Context) {
	person_code := c.PostForm("person_code")
	person_name := c.PostForm("person_name")
	data := model.PerSon{
		PerSonCode: person_code,
		PerSonName: person_name,
	}
	err := model.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
func PerSonOrderAdd(c *gin.Context) {
	order_code := c.PostForm("order_code")
	order_name := c.PostForm("order_name")
	person_id, _ := strconv.Atoi(c.PostForm("person_id"))
	data := model.Order{
		OrderCode: order_code,
		OrderName: order_name,
		PerSonId:  person_id,
	}
	err := model.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
